#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second

using namespace std;

typedef pair<int,int> pii;
const int N = 1e6 + 10;
int n,m,S,C,lim;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
string s[N];

namespace Sub1{
    vector<pii> v;
    vector<vector<bool>> vis;

    inline void solve(){
        vis.resize(n + 5);
        for (re int i = 0;i <= n + 2;i++) vis[i].resize(m + 5);
        for (re int i = 1;i <= n;i++){
            for (re int j = 1;j <= m;j++){
                if (s[i][j] == '#') v.push_back({i,j});
            }
        }
        for (re int st = 0;st < (1 << v.size());st++){
            for (re int i = 1;i <= n;i++){
                for (re int j = 1;j <= m;j++) vis[i][j] = false;
            } int cnt = __builtin_popcount(st);
            if (cnt > lim) continue;
            for (re int i = 0;i < v.size();i++){
                if ((st >> i) & 1) vis[v[i].fst][v[i].snd] = true;
            }
            for (re int i = 1;i <= n;i++){
                for (re int j = 1;j <= m;j++){
                    if (s[i][j] == '.') continue;
                    bool falg = vis[i][j];
                    for (re int d = 0;d < 4;d++){
                        int x = i + dx[d],y = j + dy[d];
                        falg |= vis[x][y];
                    }
                    if (!falg) goto End;
                }
            }
            for (re int i = 1;i <= n;i++){
                for (re int j = 1;j <= m;j++){
                    if (s[i][j] == '.') cout << '.';
                    else if (vis[i][j]) cout << '1';
                    else cout << '0';
                } cout << "\n";
            } return; End:;
        }
    }
}

namespace Sub2{
    inline void solve(){
        for (re int i = 1;i <= n;i++){
            for (re int j = 1;j <= n;j++){
                if (s[i][j] == '#') cout << '1';
                else cout << '.';
            } cout << "\n";
        }
    }
}

namespace Sub3{
    vector<vector<bool>> ans;

    inline void solve(){
        ans.resize(n + 5);
        // cerr << n << " " << m << " " << lim << " ???\n";
        for (re int i = 0;i <= n + 2;i++) ans[i].resize(m + 5);
        for (re int i = 2;i <= n;i += 3){
            for (re int j = 1;j <= m;j++) ans[i][j] = true;
        }
        if (n % 3 == 1){
            for (re int j = 2;j <= m;j += 3) ans[n][j] = true;
            if (m % 3 == 1) ans[n][m] = true;
        }
        // int cnt = 0;
        // for (re int i = 1;i <= n;i++){
        //     for (re int j = 1;j <= m;j++) cnt += ans[i][j];
        // } cerr << cnt << " ???\n";
        for (re int i = 1;i <= n;i++){
            for (re int j = 1;j <= m;j++) cout << (char)(ans[i][j] + '0');
            cout << '\n';
        }
    }
}

int main(){
    freopen("indian.in","r",stdin);
    freopen("indian.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (re int i = 1;i <= n;i++){ cin >> s[i]; s[i] = ' ' + s[i]; }
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++){
            if (s[i][j] == '#'){
                S++;
                for (re int d = 0;d < 4;d++){
                    int x = i + dx[d],y = j + dy[d];
                    if (x < 1 || x > n || y < 1 || y > m || s[x][y] != '#') C++;
                }
            }
        }
    } lim = (S + C) / 5;
    if (n * m <= 20) Sub1::solve();
    else if (S * 4 == C) Sub2::solve();
    else Sub3::solve();
    return 0;
}